建立 CoppeliaSim 4.1.0 MTB robot 場景 << 
Previous Next >> 逆向運動學函式
手臂末端加入 components-gripper-suction pad 吸盤
接續MTB Robot keyboard, 在其抓物品的桿件上加suction pad
W16_exam_MTB_robot keyboard add suction pad.7z
Lua程式:
function sysCall_init()
     axis1=sim.getObjectHandle('MTB_axis1')
     axis2=sim.getObjectHandle('MTB_axis2')
     axis3=sim.getObjectHandle('MTB_axis3')
     axis4=sim.getObjectHandle('MTB_axis4') 
     suctionPad=sim.getObjectHandle('suctionPad')     
     rotation1 = 0
     rotation2 = 0
     distance3 = 0
    -- Do some initial settings here
    -- Get object handle
      
     deg = math.pi/180
     --sim.sJointTargetVelocity(joint,5.5)
     
end
 
function sysCall_actuation()
 calibration = 0.01
 message,auxiliaryData=sim.getSimulatorMessage()
 if (message==sim.message_keypress) then
      print(auxiliaryData[1])--key
      if (auxiliaryData[1]==string.byte(' ')) then
      end
       --Display keyboard key code
      if (auxiliaryData[1]==97) then--a
      rotation1 = rotation1 + 5*deg
      sim.setJointPosition(axis1, rotation1)
      end
      -- Press the "a" key to turn axis1 5 degrees counterclockwise
      if (auxiliaryData[1]==100) then --d
      rotation1 = rotation1 - 5*deg
      sim.setJointPosition(axis1, rotation1)
      end
      -- Press the "d" key to turn axis1 5 degrees clockwise
      if (auxiliaryData[1]==119) then--w
      rotation2 = rotation2 + 5*deg
      sim.setJointPosition(axis2, rotation2)
      end
      -- Press the "w" key to turn axis2 5 degrees counterclockwise
      if (auxiliaryData[1]==115) then --s
      rotation2 = rotation2 - 5*deg
      sim.setJointPosition(axis2, rotation2)
      end
      -- Press the "s" key to turn axis2 5 degrees clockwise
      if (auxiliaryData[1]==113) then --q
      distance3 = distance3 + calibration
      sim.setJointPosition(axis3, distance3)
      end
      -- Press the "q" key to move down 0.01
      if (auxiliaryData[1]==101) then --e
      distance3 = distance3 - calibration
      sim.setJointPosition(axis3, distance3)
      end
      -- Press the "e" key to move up 0.01
      if (auxiliaryData[1]==122) then --z 
sim.setScriptSimulationParameter(sim.getScriptAssociatedWithObject(suctionPad),'active','true')
      end -- Press "z" key to activate the suction pad
      if (auxiliaryData[1]==120) then --x
sim.setScriptSimulationParameter(sim.getScriptAssociatedWithObject(suctionPad),'active','false')
      end -- Press "x" key to deactivate the suction pad
      
 end   
 
end
function sysCall_sensing()
    -- put your sensing code here
    
end
 
function sysCall_cleanup()
    -- do some clean-up here
    
end
 
建立 CoppeliaSim 4.1.0 MTB robot 場景 << 
Previous Next >> 逆向運動學函式